package com.ruoyi.categories.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.categories.domain.TbDishCategories;
import com.ruoyi.categories.service.ITbDishCategoriesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜品类别Controller
 * 
 * @author txt
 * @date 2025-02-05
 */
@Api("分类信息管理")
@RestController
@RequestMapping("/categories/categories")
public class TbDishCategoriesController extends BaseController
{
    @Autowired
    private ITbDishCategoriesService tbDishCategoriesService;

    /**
     * 查询菜品类别列表
     */
    @ApiOperation(value = "分类列表")
    @GetMapping("/list")
    public TableDataInfo list(TbDishCategories tbDishCategories)
    {
        startPage();
        List<TbDishCategories> list = tbDishCategoriesService.selectTbDishCategoriesList(tbDishCategories);
        return getDataTable(list);
    }

    /**
     * 导出菜品类别列表
     */
    @Log(title = "菜品类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDishCategories tbDishCategories)
    {
        List<TbDishCategories> list = tbDishCategoriesService.selectTbDishCategoriesList(tbDishCategories);
        ExcelUtil<TbDishCategories> util = new ExcelUtil<TbDishCategories>(TbDishCategories.class);
        util.exportExcel(response, list, "菜品类别数据");
    }

    /**
     * 获取菜品类别详细信息
     */
    @ApiOperation(value = "通过类别id拿到分类的内容")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(tbDishCategoriesService.selectTbDishCategoriesByCategoryId(categoryId));
    }

    /**
     * 新增菜品类别
     */
    @ApiOperation(value = "增加类别")
    @Log(title = "菜品类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDishCategories tbDishCategories)
    {
        return toAjax(tbDishCategoriesService.insertTbDishCategories(tbDishCategories));
    }

    /**
     * 修改菜品类别
     */
    @ApiOperation(value = "编辑类别")
    @Log(title = "菜品类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDishCategories tbDishCategories)
    {
        return toAjax(tbDishCategoriesService.updateTbDishCategories(tbDishCategories));
    }

    /**
     * 删除菜品类别
     */
    @ApiOperation(value = "删除类别")
    @Log(title = "菜品类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(tbDishCategoriesService.deleteTbDishCategoriesByCategoryIds(categoryIds));
    }
}
